package com.oromwin.repos.server.response.media;

import java.io.DataInputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;

import com.oromwin.repos.common.Logger;
import com.oromwin.repos.common.ReposException;
import com.oromwin.repos.common.helper.IOHelper;
import com.oromwin.repos.data.FileTable;
import com.oromwin.repos.server.response.NormalResponse;

public class ListMediaResponse extends NormalResponse {
    private Log log = Logger.getLog(ListMediaResponse.class);
    private int size = 0;
    private List fileTableList = null;
    
    public ListMediaResponse() {
        fileTableList = new ArrayList();
    }
    
    public void receive(DataInputStream dis) throws ReposException {
        try {
            Result = dis.readBoolean();
            Description = IOHelper.readUTF8(dis);
            size = dis.readInt();
            for (int i = 0; i < size; i++) {
                String volumeId = IOHelper.readUTF8(dis);
                String mediaId = IOHelper.readUTF8(dis);
                String fileId = IOHelper.readUTF8(dis);
                String fileName = IOHelper.readUTF8(dis);
                String fileFormat = IOHelper.readUTF8(dis);
                File filePath = new File(IOHelper.readUTF8(dis));
                Long fileBytes = new Long(dis.readLong());
                String fileCategory = IOHelper.readUTF8(dis);
                Boolean fileStatus = new Boolean(dis.readBoolean());
                Boolean filePdfConvFlag = new Boolean(dis.readBoolean());
                Boolean fileCompressionFlag = new Boolean(dis.readBoolean());
                String fileCreateDate = IOHelper.readUTF8(dis);
                String fileUpdateDate = IOHelper.readUTF8(dis);
                FileTable fileTable = new FileTable(volumeId, mediaId, fileId, fileName, fileFormat, filePath, fileBytes, fileCategory, fileStatus, filePdfConvFlag, fileCompressionFlag, fileCreateDate, fileUpdateDate);
                fileTableList.add(fileTable);
            }
        } catch (IOException e) {
            throw ReposException.create(log, e);
        }
    }
    public List getFileTableList() {
        return fileTableList;
    }
}
